﻿#ifndef DATASIMUSTORAGE_H
#define DATASIMUSTORAGE_H

#include <QSettings>
#include <QMutex>
#include <QFile>
#include <QDataStream>
#include <QTextStream>

#include "enum.h"
#include "datastruct.h"

class DataSimuStorage : public QObject
{
    Q_OBJECT
public:
    explicit DataSimuStorage(QSettings* settings, QList<ChannelDescription> channelDescriptionList, QList<ReportLine> reportLineList, QObject *parent = nullptr);
    ~DataSimuStorage();

private:
    void init();
    void storageReport();

private:
    // INI配置文件
    QSettings* m_settings;

    // 通道描述列表
    QList<ChannelDescription> m_channelDescriptionList;

    // 报表行描述列表
    QList<ReportLine> m_reportLineList;

    // 测试级别
    //int m_level;

    // 标识是否已经创建并打开了文件
    bool m_opened;

    // 二进制数据文件
    QString m_savePath;
    QFile* m_dataFile;
    QDataStream* m_dataStream;

    // csv报表数据文件
    QString m_reportPath;
    QFile* m_reportFile;
    QTextStream* m_reportStream;


signals:
    void sigErrorOccurred(QString error);

public slots:
    void onOpen();
    void onClose();
    void onStorage(const qint64 timeStamp, const QVariantList valueList);

};

#endif // DATASIMUSTORAGE_H
